{% extends 'store/blank.html' %}
{% block contenter %}
    <style>
        td, th {
            text-align: center;
        }
    </style>
    <div class="container-fluid">
        <div class="row">
            <button class="btn btn-primary col-lg-2 ml-auto" data-toggle="modal" data-target="#goods_modal">添加类型
            </button>
        </div>
        <div class="row">
            <table class="table">
                <thead>
                <tr>
                    <th>类型序号</th>
                    <th>类型名称</th>
                    <th>类型图片</th>
                    <th>类型图标</th>
                    <th>操作</th>
                </tr>
                </thead>

                <tbody>
                {% for t in type_list %}
                    <tr>
                        <td class="t_id">{{ t.id }}</td>
                        <td class="type">{{ t.type }}</td>
                        <td class="picture"><img src="/static/{{ t.t_picture }}" width="50px"></td>
                        <td class="logo"><img src="/static/{{ t.t_logo }}"></td>
                        <td>
                            <a class="btn" data-toggle="modal" data-target="#goods_modal" onclick="edit(this)">编辑</a>
                            <a class="btn" href="/store/delete_type/{{ t.id }}">删除</a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
            <div class="modal fade" id="goods_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
                 aria-label="true">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">类型操作</div>
                        <form method="post" enctype="multipart/form-data" action="/store/type_manage/">
                            {% csrf_token %}
                            <div class="modal-body">
                                <div class="form-group">
                                    <label class="">类型序号</label>
                                    <input class="form-control" type="text" name="t_id" id="type_id" style="display: none">
                                    <label class="">类型名称</label>
                                    <input class="form-control" type="text" name="t_type" id="t_type">
                                </div>
                                <div class="form-group">
                                    <label class="">类型图片</label>
                                    <input class="form-control " type="file" name="t_picture" id="t_picture">
                                </div>
                                <div class="form-group">
                                    <label class="">类型图标</label>
                                    <input class="form-control" type="file" name="t_logo" id="t_logo">
                                </div>
                                <button class="btn btn-primary fa-pull-right" >提交类型</button>
                            </div>
                        </form>

                    </div>

                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block script %}
    <script>
        function edit(obj) {
            $('#type_id').val($(obj).parent().siblings('.t_id').text());
            $('#t_type').val($(obj).parent().siblings('.type').text());
        }
    </script>
{% endblock %}